libobs_wrapper\display\window_manager/
misc_trait.rs

1use crate::display::window_manager::MiscDisplayTrait;
2use crate::display::ObsDisplayRef;
3use crate::run_with_obs;
4use crate::utils::ObsError;
5
6impl MiscDisplayTrait for ObsDisplayRef {
7    fn is_enabled(&self) -> Result<bool, ObsError> {
8        let display_ptr = self.as_ptr();
9        run_with_obs!(self.runtime, (display_ptr), move || {
10            unsafe {
11                // Safety: The pointer is valid because we are using a smart pointer
12                libobs::obs_display_enabled(display_ptr.get_ptr())
13            }
14        })
15    }
16
17    fn set_enabled(&self, enabled: bool) -> Result<(), ObsError> {
18        let display_ptr = self.as_ptr();
19
20        run_with_obs!(self.runtime, (display_ptr), move || {
21            unsafe {
22                // Safety: The pointer is valid because we are using a smart pointer
23                libobs::obs_display_set_enabled(display_ptr.get_ptr(), enabled)
24            }
25        })
26    }
27
28    fn set_background_color(&self, r: u8, g: u8, b: u8) -> Result<(), ObsError> {
29        let color: u32 = ((r as u32) << 16) | ((g as u32) << 8) | (b as u32);
30        let display_ptr = self.as_ptr();
31
32        run_with_obs!(self.runtime, (display_ptr), move || {
33            unsafe {
34                // Safety: The pointer is valid because we are using a smart pointer and the color is literally just a number
35                libobs::obs_display_set_background_color(display_ptr.get_ptr(), color)
36            }
37        })
38    }
39}